#ifndef GL_CONSOLE_H
#define GL_CONSOLE_H

#include "../../../../Base/Drawable.h"
#include "../Console/GLConsole.h"
#include "../../../../Math/Area.h"
//#include "../../../../GLDriver/GLDriverComponents/ErrorHandler/ErrorEvent.h"
#include "../../../../GLApp/GLAppComponents/GLWindow/GLWindow.h"
#include "../../../../GLScene/GLSceneComponents/2D/BitmapFont/GLBitmapFont.h"
#include "../../../../GLApp/GLAppComponents/GLInput/GLInputManager.h"
#include "../../../../GLApp/GLAppComponents/GLInput/GLKeyboardEvent.h"
#include "../../../../GLApp/GLAppComponents/GLInput/GLDirectKeyboardInput.h"

#include <string>

#define MPCON_LINE_MAX			128
#define MPCON_OUTPUT_MAX_LINES	128

using namespace mp_base;
using namespace mp_math;
//using mp_error::ErrorEvent;
using std::string;

namespace mp_gl
{
	/*!----------------------------------------------------------------
	*	@class		GLConsole
	*	@brief		Overlay Console for general use.
	*
	*	@author		Mitchell Pell
	*	@date		9/28/2013
	*	@version	1.0
	*
	----------------------------------------------------------------*/
	class GLConsole : public Drawable
	{
	public:
		GLConsole();
		virtual ~GLConsole();

		void SetWindow(GLFWwindow* window){m_window = window;}
		void SetInputHandler(GLInputManager* inputManager)
			{ m_inputManager = inputManager;}
		void SetglOrtho(double left, double right, 
			double bottom, double top, double zNear, double zFar);
		void SetFont(char* fileDir);
		void BindFonts(){m_font->Select();}
		//void SetErrorEvent(ErrorEvent* erevnt)
			//{m_errorEvent = erevnt;}

		virtual void Initialize();
		virtual void LoadContent();
		virtual void Uninitialize(){}
		virtual void UnloadContent(){}
		virtual void Update();
		virtual void Draw();
		
		virtual void ProcessInput();

		void DrawOutputText(const Area area);
		void DrawInputText(const Area area);
		void DrawOutputLine(const Area area, const unsigned int index);

		void WriteLine(const string line);
		void WriteLine(const string* const line);


	protected:
		//ErrorEvent*				m_errorEvent;
		/*!  */
		GLFWwindow*				m_window;
		/*!  */
		GLInputManager*			m_inputManager;
		
		/*! Area of the console window. */
		Area					m_area;

		/*! Directory of the bitmap font */
		char*					m_fontDir;
		/*! Consoles bitmap font for rendering. */
		GLBitmapFont*			m_font;

		/*! Input text from the console. */
		string*					m_input;
		/*!  */
		string**				m_inputBuffer;

		/*! Output text from the console. */
		string**				m_output;
		/*!  */
		unsigned int			m_outputLine;
		/*! Total output lines */
		unsigned int			m_outputLineCount;

		/*! Button bind for opening and closing the console. */
		spGLButtonEvent			m_btnConEvent;
		/*! */
		spGLButtonEvent			m_btnBackspaceEvent;
		/*! */
		spGLButtonEvent			m_btnEnterEvent;
		/*! Direct keyboard input. */
		spGLDirectKeyboardInput	m_directChar;
	};
}

#endif